package za.co.green;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class ServerFileRequestThread extends Thread {
	
	SocketChannel chan = null;
	
	public ServerFileRequestThread() throws IOException {
		this("FileRequestThread");
	 }
	
	public ServerFileRequestThread(SocketChannel chan) throws IOException {
		super("FileRequestThread");
		
		this.chan = chan;
	 }
	
	public ServerFileRequestThread(String name) {
        super(name);
    }
	
	public void run() {
		try {
		// THIS IS THE SERVER
			
			ObjectInputStream ois = 
                     new ObjectInputStream(chan.socket().getInputStream());
    		
    		String s = (String)ois.readObject();
    		System.out.println("ServerFileRequestThread >>>  String is: '" + s + "'");
    		
    		ObjectOutputStream oos =
    				new ObjectOutputStream(chan.socket().getOutputStream());
    		
    		String someDummyFile = "qwerty";
    		
    		oos.writeObject(someDummyFile);
        
		} catch (Exception e) {e.printStackTrace(); return;}
	}

}
